package com.lry.basic.thread;



/**
 * @author:刘仁有
 * @desc:
 * @email:953506233@qq.com
 * @data:2020/1/6
 */
//一个线程打印1 2 3 ...
//一个线程打印a b c ...
//交替打印 1 a 2 b 3 c  ... 直到所有字母打印完毕
public class Thread3 {
    private static int index = 1;
    private static volatile boolean f = true;

    public static void main(String[] args) {
        new Thread(){
            @Override
            public void run() {
                while(index<=26){
                    if(f){
                        System.out.println(index++);
                        f = false;
                    }
                }
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                while(index<=27){
                    if(!f){
                        System.out.println((char)('a'+index-2));
                        f = true;
                        if(index==27)break;
                    }

                }
            }
        }.start();
    }
}
